package com.jinzhi.jzweb.controller;


import java.util.*;

import com.jinzhi.jzweb.domain.vo.JazCoursesOrdeVo;
import com.jinzhi.jzweb.domain.vo.JazGroupActivityVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazCoursesOrderDO;
import com.jinzhi.jzweb.service.JazCoursesOrderService;
import com.jinzhi.common.utils.Result;

/**
 * <pre>
 * 课程订单表
 * </pre>
 * <small> 2024-05-16 11:35:43 | Long</small>
 */
@Controller
@RequestMapping("/jzweb/jazCoursesOrder")
public class JazCoursesOrderController extends BaseController {
    @Autowired
    private JazCoursesOrderService jazCoursesOrderService;

    @GetMapping()
    @RequiresPermissions("jzweb:jazCoursesOrder:jazCoursesOrder")
    String JazCoursesOrder(Model model) {
        model.addAttribute("type", "课程");
        return "jzweb/jazGroupActivity/jazGroupActivity";
    }

    @ResponseBody
//	@GetMapping("/list")
//	@RequiresPermissions("jzweb:jazCoursesOrder:jazCoursesOrder")
    public Result<Page<JazCoursesOrderDO>> list(JazCoursesOrderDO jazCoursesOrderDTO) {
        // 查询列表数据
        Page<JazCoursesOrderDO> page = jazCoursesOrderService.selectPage(getPage(JazCoursesOrderDO.class),
                jazCoursesOrderService.convertToEntityWrapper().orderBy("id", false));
        List list = new ArrayList();
        for (int i = 0; i < page.getRecords().size(); i++) {
            JazCoursesOrderDO obj = (JazCoursesOrderDO) page.getRecords().get(i);
            list.add(obj);
        }
        page.setRecords(list);
        return Result.ok(page);
    }


    /**
     * 课程订单查询
     *
     * @return
     */
    @GetMapping("/selCourseOrderList")
    @ResponseBody
    public Result<Page<JazCoursesOrderDO>> selCourseOrderList(@RequestParam(value = "name", required = false) String name,
                                                             @RequestParam(value = "mobile", required = false) String mobile,
                                                             @RequestParam("current") int current,
                                                             @RequestParam("size") int size,
                                                             @RequestParam(value = "createTime", required = false) String createTime,
                                                             @RequestParam(value = "endTime", required = false) String endTime,
                                                             @RequestParam(value = "status", required = false) String status
                                                             ) {

        return jazCoursesOrderService.selCourseOrderList(name, mobile, current, size,createTime,endTime,status);
    }

    /**
     *  课程订单详情
     * @return
     */
    @GetMapping("/getInfo")
    public Result<?> getInfo(@RequestParam("id")Long id )  {
        JazCoursesOrdeVo vo=jazCoursesOrderService.getInfo(id);
        return Result.ok(vo);

    }
    @GetMapping("/add")
    @RequiresPermissions("jzweb:jazCoursesOrder:add")
    String add() {
        return "jzweb/jazCoursesOrder/add";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("jzweb:jazCoursesOrder:edit")
    String edit(@PathVariable("id") Long id, Model model) {
        JazCoursesOrderDO jazCoursesOrder = jazCoursesOrderService.selectById(id);
        model.addAttribute("jazCoursesOrder", jazCoursesOrder);
        return "jzweb/jazCoursesOrder/edit";
    }

    @Log(value = "添加课程订单",sysModule = 5,operationType = 1)
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("jzweb:jazCoursesOrder:add")
    public Result<String> save(JazCoursesOrderDO jazCoursesOrder) {
        jazCoursesOrderService.insert(jazCoursesOrder);
        return Result.ok();
    }

    @Log(value = "修改课程订单",sysModule = 5,operationType = 3)
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("jzweb:jazCoursesOrder:edit")
    public Result<String> update(JazCoursesOrderDO jazCoursesOrder) {
        boolean update = jazCoursesOrderService.updateById(jazCoursesOrder);
        return update ? Result.ok() : Result.fail();
    }

    @Log(value = "删除课程订单",sysModule = 5,operationType = 2)
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("jzweb:jazCoursesOrder:remove")
    public Result<String> remove(Long id) {
        jazCoursesOrderService.deleteById(id);
        return Result.ok();
    }

    @Log(value = "批量删除课程订单",sysModule = 5,operationType = 2)
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("jzweb:jazCoursesOrder:batchRemove")
    public Result<String> remove(@RequestParam("ids[]") Long[] ids) {
        jazCoursesOrderService.deleteBatchIds(Arrays.asList(ids));
        return Result.ok();
    }

}
